package org.example.netty.reactor;

import lombok.extern.slf4j.Slf4j;
import sun.nio.ch.sctp.SctpStdSocketOption;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Set;

/**
 * 单线程Reactor
 */
@Slf4j
public class SingleThreadReactor {
    public static void main(String[] args) {
        Selector selector = null;
        ServerSocketChannel serverSocketChannel = null;
        try {
            selector = Selector.open();
            serverSocketChannel = ServerSocketChannel.open();
            serverSocketChannel.configureBlocking(false);
            // 发送缓冲区大小
            final SelectionKey selectionKey = serverSocketChannel.register(selector, 0);
            serverSocketChannel.bind(new InetSocketAddress("localhost", 8081));
            // bind成功之后注册OP_ACCEPT事件
            selectionKey.interestOps(SelectionKey.OP_ACCEPT);

            while (true) {
                selector.select();
                final Set<SelectionKey> selectedKeys = selector.selectedKeys();
                final Iterator<SelectionKey> iterator = selectedKeys.iterator();
                if (!selectedKeys.isEmpty()) {
                    while (iterator.hasNext()) {
                        final SelectionKey selectedKey = iterator.next();
                        if (selectedKey.isAcceptable()) {
                            log.info("有新的连接进来");
                            final SelectableChannel channel = selectedKey.channel();
                            if (channel instanceof ServerSocketChannel) {
                                ServerSocketChannel serverChannel = (ServerSocketChannel) channel;
                                final SocketChannel socketChannel = serverChannel.accept();
                                socketChannel.configureBlocking(false);
                                socketChannel.register(selector, SelectionKey.OP_READ);
                            }
                        } else if (selectedKey.isReadable()) {
                            log.info("有数据可以读");
                            SocketChannel socketChannel = (SocketChannel) selectedKey.channel();
                            // 1024个字节读取
                            int defaultSize = 1024;
                            int length = 0;
                            // 说明还有的读取
                            while (!(length < 0)) {
                                // 开始读数据
                                ByteBuffer buffer = ByteBuffer.allocate(defaultSize);
                                length = socketChannel.read(buffer);
                                if (length <= 0) {
                                    // 清空buffer数据
                                    buffer = null;
                                    break;
                                }
                                buffer.flip();
                                // 将buffer的内容转成字符串
                                byte[] contents = new byte[buffer.limit() - buffer.position()];
                                buffer.get(contents);
                                log.info("读取的数据内容：{}", new String(contents));
                                buffer.clear();
                                buffer = null;
                                defaultSize = defaultSize << 1;
                            }

                            // 读取完毕，可以写数据
                            // String content = "{\"data\":{\"zu\":{\"types\":{\"language\":{\"long\":{\"aa\":\"isi-Afar\",\"ab\":\"isi-Abkhazian\",\"ace\":\"isi-Achinese\",\"ach\":\"isi-Acoli\",\"ada\":\"isi-Adangme\",\"ady\":\"isi-Adyghe\",\"af\":\"i-Afrikaans\",\"agq\":\"isi-Aghem\",\"ain\":\"isi-Ainu\",\"ak\":\"isi-Akan\",\"ale\":\"isi-Aleut\",\"alt\":\"isi-Southern Altai\",\"am\":\"isi-Amharic\",\"an\":\"isi-Aragonese\",\"anp\":\"isi-Angika\",\"ar\":\"isi-Arabic\",\"ar-001\":\"isi-Arabic esivamile sesimanje\",\"arn\":\"isi-Mapuche\",\"arp\":\"isi-Arapaho\",\"as\":\"isi-Assamese\",\"asa\":\"isi-Asu\",\"ast\":\"isi-Asturian\",\"av\":\"isi-Avaric\",\"awa\":\"isi-Awadhi\",\"ay\":\"isi-Aymara\",\"az\":\"isi-Azerbaijani\",\"ba\":\"isi-Bashkir\",\"ban\":\"isi-Balinese\",\"bas\":\"isi-Basaa\",\"be\":\"isi-Belarusian\",\"bem\":\"isi-Bemba\",\"bez\":\"isi-Bena\",\"bg\":\"isi-Bulgari\",\"bgn\":\"isi-Western Balochi\",\"bho\":\"isi-Bhojpuri\",\"bi\":\"isi-Bislama\",\"bin\":\"isi-Bini\",\"bla\":\"isi-Siksika\",\"bm\":\"isi-Bambara\",\"bn\":\"isi-Bengali\",\"bo\":\"isi-Tibetan\",\"br\":\"isi-Breton\",\"brx\":\"isi-Bodo\",\"bs\":\"isi-Bosnian\",\"bug\":\"isi-Buginese\",\"byn\":\"isi-Blin\",\"ca\":\"isi-Catalan\",\"ccp\":\"i-Chakma\",\"ce\":\"isi-Chechen\",\"ceb\":\"isi-Cebuano\",\"cgg\":\"isi-Chiga\",\"ch\":\"isi-Chamorro\",\"chk\":\"isi-Chuukese\",\"chm\":\"isi-Mari\",\"cho\":\"isi-Choctaw\",\"chr\":\"isi-Cherokee\",\"chy\":\"isi-Cheyenne\",\"ckb\":\"isi-Central Kurdish\",\"co\":\"isi-Corsican\",\"crs\":\"i-Seselwa Creole French\",\"cs\":\"isi-Czech\",\"cu\":\"isi-Church Slavic\",\"cv\":\"isi-Chuvash\",\"cy\":\"isi-Welsh\",\"da\":\"isi-Danish\",\"dak\":\"isi-Dakota\",\"dar\":\"isi-Dargwa\",\"dav\":\"isi-Taita\",\"de\":\"isi-German\",\"de-AT\":\"isi-Austrian German\",\"de-CH\":\"Isi-Swiss High German\",\"dgr\":\"isi-Dogrib\",\"dje\":\"isi-Zarma\",\"dsb\":\"isi-Lower Sorbian\",\"dua\":\"isi-Duala\",\"dv\":\"isi-Divehi\",\"dyo\":\"isi-Jola-Fonyi\",\"dz\":\"isi-Dzongkha\",\"dzg\":\"isi-Dazaga\",\"ebu\":\"isi-Embu\",\"ee\":\"isi-Ewe\",\"efi\":\"isi-Efik\",\"eka\":\"isi-Ekajuk\",\"el\":\"isi-Greek\",\"en\":\"i-English\",\"en-AU\":\"i-Australian English\",\"en-CA\":\"i-Canadian English\",\"en-GB\":\"i-British English\",\"en-US\":\"i-American English\",\"eo\":\"isi-Esperanto\",\"es\":\"isi-Spanish\",\"es-419\":\"isi-Latin American Spanish\",\"es-ES\":\"isi-European Spanish\",\"es-MX\":\"Isi-Mexican Spanish\",\"et\":\"isi-Estonia\",\"eu\":\"isi-Basque\",\"ewo\":\"isi-Ewondo\",\"fa\":\"isi-Persian\",\"ff\":\"isi-Fulah\",\"fi\":\"isi-Finnish\",\"fil\":\"isi-Filipino\",\"fj\":\"isi-Fijian\",\"fo\":\"isi-Faroese\",\"fon\":\"isi-Fon\",\"fr\":\"isi-French\",\"fr-CA\":\"isi-Canadian French\",\"fr-CH\":\"isi-Swiss French\",\"frc\":\"frc\",\"fur\":\"isi-Friulian\",\"fy\":\"isi-Western Frisian\",\"ga\":\"isi-Irish\",\"gaa\":\"isi-Ga\",\"gag\":\"isi-Gagauz\",\"gan\":\"isi-Gan Chinese\",\"gd\":\"isi-Scottish Gaelic\",\"gez\":\"isi-Geez\",\"gil\":\"isi-Gilbertese\",\"gl\":\"isi-Galicia\",\"gn\":\"isi-Guarani\",\"gor\":\"isi-Gorontalo\",\"gsw\":\"isi-Swiss German\",\"gu\":\"isi-Gujarati\",\"guz\":\"isi-Gusli\",\"gv\":\"isi-Manx\",\"gwi\":\"isi-Gwichʼin\",\"ha\":\"isi-Hausa\",\"hak\":\"isi-Hakka Chinese\",\"haw\":\"isi-Hawaiian\",\"he\":\"isi-Hebrew\",\"hi\":\"isi-Hindi\",\"hil\":\"isi-Hiligaynon\",\"hmn\":\"isi-Hmong\",\"hr\":\"isi-Croatian\",\"hsb\":\"isi-Upper Sorbian\",\"hsn\":\"isi-Xiang Chinese\",\"ht\":\"isi-Haitian\",\"hu\":\"isi-Hungarian\",\"hup\":\"isi-Hupa\",\"hy\":\"isi-Armenia\",\"hz\":\"isi-Herero\",\"ia\":\"izilimi ezihlangene\",\"iba\":\"isi-Iban\",\"ibb\":\"isi-Ibibio\",\"id\":\"isi-Indonesian\",\"ie\":\"izimili\",\"ig\":\"isi-Igbo\",\"ii\":\"isi-Sichuan Yi\",\"ilo\":\"isi-Iloko\",\"inh\":\"isi-Ingush\",\"io\":\"isi-Ido\",\"is\":\"isi-Icelandic\",\"it\":\"isi-Italian\",\"iu\":\"isi-Inuktitut\",\"ja\":\"isi-Japanese\",\"jbo\":\"isi-Lojban\",\"jgo\":\"isi-Ngomba\",\"jmc\":\"isi-Machame\",\"jv\":\"isi-Javanese\",\"ka\":\"isi-Georgian\",\"kab\":\"isi-Kabyle\",\"kac\":\"isi-Kachin\",\"kaj\":\"isi-Jju\",\"kam\":\"isi-Kamba\",\"kbd\":\"isi-Kabardian\",\"kcg\":\"isi-Tyap\",\"kde\":\"isi-Makonde\",\"kea\":\"isi-Kabuverdianu\",\"kfo\":\"isi-Koro\",\"kg\":\"isi-Kongo\",\"kha\":\"isi-Khasi\",\"khq\":\"isi-Koyra Chiini\",\"ki\":\"isi-Kikuyu\",\"kj\":\"isi-Kuanyama\",\"kk\":\"isi-Kazakh\",\"kkj\":\"isi-Kako\",\"kl\":\"isi-Kalaallisut\",\"kln\":\"isi-Kalenjin\",\"km\":\"isi-Khmer\",\"kmb\":\"isi-Kimbundu\",\"kn\":\"isi-Kannada\",\"ko\":\"isi-Korean\",\"koi\":\"isi-Komi-Permyak\",\"kok\":\"isi-Konkani\",\"kpe\":\"isi-Kpelle\",\"kr\":\"isi-Kanuri\",\"krc\":\"isi-Karachay-Balkar\",\"krl\":\"isi-Karelian\",\"kru\":\"isi-Kurukh\",\"ks\":\"isi-Kashmiri\",\"ksb\":\"isiShambala\",\"ksf\":\"isi-Bafia\",\"ksh\":\"isi-Colognian\",\"ku\":\"isi-Kurdish\",\"kum\":\"isi-Kumyk\",\"kv\":\"isi-Komi\",\"kw\":\"isi-Cornish\",\"ky\":\"isi-Kyrgyz\",\"la\":\"isi-Latin\",\"lad\":\"isi-Ladino\",\"lag\":\"isi-Langi\",\"lb\":\"isi-Luxembourgish\",\"lez\":\"isi-Lezghian\",\"lg\":\"isi-Ganda\",\"li\":\"isi-Limburgish\",\"lkt\":\"isi-Lakota\",\"ln\":\"isi-Lingala\",\"lo\":\"isi-Lao\",\"lou\":\"lou\",\"loz\":\"isi-Lozi\",\"lrc\":\"isi-Northern Luri\",\"lt\":\"isi-Lithuanian\",\"lu\":\"isi-Luba-Katanga\",\"lua\":\"isi-Luba-Lulua\",\"lun\":\"isi-Lunda\",\"luo\":\"isi-Luo\",\"lus\":\"isi-Mizo\",\"luy\":\"isi-Luyia\",\"lv\":\"isi-Latvian\",\"mad\":\"isi-Madurese\",\"mag\":\"isi-Magahi\",\"mai\":\"isi-Maithili\",\"mak\":\"isi-Makasar\",\"mas\":\"isi-Masai\",\"mdf\":\"isi-Moksha\",\"men\":\"isi-Mende\",\"mer\":\"isi-Meru\",\"mfe\":\"isi-Morisyen\",\"mg\":\"isi-Malagasy\",\"mgh\":\"isi-Makhuwa-Meetto\",\"mgo\":\"isi-Meta’\",\"mh\":\"isi-Marshallese\",\"mi\":\"isi-Maori\",\"mic\":\"isi-Micmac\",\"min\":\"isi-Minangkabau\",\"mk\":\"isi-Macedonian\",\"ml\":\"isi-Malayalam\",\"mn\":\"isi-Mongolian\",\"mni\":\"isi-Manipuri\",\"moh\":\"isi-Mohawk\",\"mos\":\"isi-Mossi\",\"mr\":\"isi-Marathi\",\"ms\":\"isi-Malay\",\"mt\":\"isi-Maltese\",\"mua\":\"isi-Mundang\",\"mul\":\"izilimi ezehlukene\",\"mus\":\"isi-Creek\",\"mwl\":\"isi-Mirandese\",\"my\":\"isi-Burmese\",\"myv\":\"isi-Erzya\",\"mzn\":\"isi-Mazanderani\",\"na\":\"isi-Nauru\",\"nan\":\"isi-Min Nan Chinese\",\"nap\":\"isi-Neapolitan\",\"naq\":\"isi-Nama\",\"nb\":\"isi-Norwegian Bokmål\",\"nd\":\"isi-North Ndebele\",\"nds\":\"isi-Low German\",\"nds-NL\":\"isi-Low Saxon\",\"ne\":\"isi-Nepali\",\"new\":\"isi-Newari\",\"ng\":\"isi-Ndonga\",\"nia\":\"isi-Nias\",\"niu\":\"isi-Niuean\",\"nl\":\"isi-Dutch\",\"nl-BE\":\"isi-Flemish\",\"nmg\":\"isi-Kwasio\",\"nn\":\"isi-Norwegian Nynorsk\",\"nnh\":\"isi-Ngiemboon\",\"no\":\"isi-Norwegian\",\"nog\":\"isi-Nogai\",\"nqo\":\"isi-N’Ko\",\"nr\":\"isi-South Ndebele\",\"nso\":\"isi-Northern Sotho\",\"nus\":\"isi-Nuer\",\"nv\":\"isi-Navajo\",\"ny\":\"isi-Nyanja\",\"nyn\":\"isi-Nyankole\",\"oc\":\"isi-Occitan\",\"om\":\"isi-Oromo\",\"or\":\"isi-Odia\",\"os\":\"isi-Ossetic\",\"pa\":\"isi-Punjabi\",\"pag\":\"isi-Pangasinan\",\"pam\":\"isi-Pampanga\",\"pap\":\"isi-Papiamento\",\"pau\":\"isi-Palauan\",\"pcm\":\"isi-Nigerian Pidgin\",\"pl\":\"isi-Polish\",\"prg\":\"isi-Prussian\",\"ps\":\"isi-Pashto\",\"pt\":\"isi-Portuguese\",\"pt-BR\":\"isi-Brazillian Portuguese\",\"pt-PT\":\"isi-European Portuguese\",\"qu\":\"isi-Quechua\",\"quc\":\"isi-Kʼicheʼ\",\"rap\":\"isi-Rapanui\",\"rar\":\"isi-Rarotongan\",\"rm\":\"isi-Romansh\",\"rn\":\"isi-Rundi\",\"ro\":\"isi-Romanian\",\"ro-MD\":\"isi-Moldavian\",\"rof\":\"isi-Rombo\",\"root\":\"isi-Root\",\"ru\":\"isi-Russian\",\"rup\":\"isi-Aromanian\",\"rw\":\"isi-Kinyarwanda\",\"rwk\":\"isi-Rwa\",\"sa\":\"isi-Sanskrit\",\"sad\":\"isi-Sandawe\",\"sah\":\"i-Sakha\",\"saq\":\"isi-Samburu\",\"sat\":\"isi-Santali\",\"sba\":\"isi-Ngambay\",\"sbp\":\"isi-Sangu\",\"sc\":\"isi-Sardinian\",\"scn\":\"isi-Sicilian\",\"sco\":\"isi-Scots\",\"sd\":\"isi-Sindhi\",\"sdh\":\"i-Southern Kurdish\",\"se\":\"isi-Northern Sami\",\"seh\":\"isi-Sena\",\"ses\":\"isi-Koyraboro Senni\",\"sg\":\"isi-Sango\",\"sh\":\"isi-Serbo-Croatian\",\"shi\":\"isi-Tachelhit\",\"shn\":\"isi-Shan\",\"si\":\"isi-Sinhala\",\"sk\":\"isi-Slovak\",\"sl\":\"isi-Slovenian\",\"sm\":\"isi-Samoan\",\"sma\":\"isi-Southern Sami\",\"smj\":\"isi-Lule Sami\",\"smn\":\"isi-Inari Sami\",\"sms\":\"isi-Skolt Sami\",\"sn\":\"isiShona\",\"snk\":\"isi-Soninke\",\"so\":\"isi-Somali\",\"sq\":\"isi-Albania\",\"sr\":\"isi-Serbian\",\"srn\":\"isi-Sranan Tongo\",\"ss\":\"isiSwati\",\"ssy\":\"isi-Saho\",\"st\":\"isi-Southern Sotho\",\"su\":\"isi-Sundanese\",\"suk\":\"isi-Sukuma\",\"sv\":\"isi-Swedish\",\"sw\":\"isiSwahili\",\"sw-CD\":\"isi-Congo Swahili\",\"swb\":\"isi-Comorian\",\"syr\":\"isi-Syriac\",\"ta\":\"isi-Tamil\",\"te\":\"isi-Telugu\",\"tem\":\"isi-Timne\",\"teo\":\"isi-Teso\",\"tet\":\"isi-Tetum\",\"tg\":\"isi-Tajik\",\"th\":\"isi-Thai\",\"ti\":\"isi-Tigrinya\",\"tig\":\"isi-Tigre\",\"tk\":\"isi-Turkmen\",\"tlh\":\"isi-Klingon\",\"tn\":\"isi-Tswana\",\"to\":\"isi-Tongan\",\"tpi\":\"isi-Tok Pisin\",\"tr\":\"isi-Turkish\",\"trv\":\"isi-Taroko\",\"ts\":\"isi-Tsonga\",\"tt\":\"isi-Tatar\",\"tum\":\"isi-Tumbuka\",\"tvl\":\"isi-Tuvalu\",\"tw\":\"isi-Twi\",\"twq\":\"isi-Tasawaq\",\"ty\":\"isi-Tahitian\",\"tyv\":\"isi-Tuvinian\",\"tzm\":\"isi-Central Atlas Tamazight\",\"udm\":\"isi-Udmurt\",\"ug\":\"isi-Uighur\",\"uk\":\"isi-Ukrainian\",\"umb\":\"isi-Umbundu\",\"und\":\"ulimi olungaziwa\",\"ur\":\"isi-Urdu\",\"uz\":\"isi-Uzbek\",\"vai\":\"isi-Vai\",\"ve\":\"isi-Venda\",\"vi\":\"isi-Vietnamese\",\"vo\":\"isi-Volapük\",\"vun\":\"isiVunjo\",\"wa\":\"isi-Walloon\",\"wae\":\"isi-Walser\",\"wal\":\"isi-Wolaytta\",\"war\":\"isi-Waray\",\"wbp\":\"isi-Warlpiri\",\"wo\":\"isi-Wolof\",\"wuu\":\"isi-Wu Chinese\",\"xal\":\"isi-Kalmyk\",\"xh\":\"isiXhosa\",\"xog\":\"isi-Soga\",\"yav\":\"isi-Yangben\",\"ybb\":\"isi-Yemba\",\"yi\":\"isi-Yiddish\",\"yo\":\"isi-Yoruba\",\"yue\":\"isi-Cantonese\",\"zgh\":\"isi-Moroccan Tamazight esivamile\",\"zh\":\"isi-Chinese\",\"zh-Hans\":\"isi-Chinese (esenziwe-lula)\",\"zh-Hant\":\"isi-Chinese (Okosiko)\",\"zu\":\"isiZulu\",\"zun\":\"isi-Zuni\",\"zxx\":\"akukho okuqukethwe kolimi\",\"zza\":\"isi-Zaza\"},\"short\":{\"az\":\"isi-Azeria\",\"en-GB\":\"i-UK English\",\"en-US\":\"i-English (US)\"},\"narrow\":{}},\"region\":{\"long\":{\"142\":\"i-Asia\",\"143\":\"i-Central Asia\",\"145\":\"i-Western Asia\",\"150\":\"i-Europe\",\"151\":\"i-Eastern Europe\",\"154\":\"i-Northern Europe\",\"155\":\"i-Western Europe\",\"202\":\"Sub-Saharan Africa\",\"419\":\"i-Latin America\",\"001\":\"umhlaba\",\"002\":\"i-Africa\",\"003\":\"i-North America\",\"005\":\"i-South America\",\"009\":\"i-Oceania\",\"011\":\"i-Western Africa\",\"013\":\"i-Central America\",\"014\":\"i-Eastern Africa\",\"015\":\"i-Northern Africa\",\"017\":\"i-Middle Africa\",\"018\":\"i-Southern Africa\",\"019\":\"i-Americas\",\"021\":\"i-Northern America\",\"029\":\"i-Caribbean\",\"030\":\"i-Eastern Asia\",\"034\":\"i-Southern Asia\",\"035\":\"i-South-Eastern Asia\",\"039\":\"i-Southern Europe\",\"053\":\"i-Australasia\",\"054\":\"i-Melanesia\",\"057\":\"i-Micronesian Region\",\"061\":\"i-Polynesia\",\"AC\":\"i-Ascension Island\",\"AD\":\"i-Andorra\",\"AE\":\"i-United Arab Emirates\",\"AF\":\"i-Afghanistan\",\"AG\":\"i-Antigua ne-Barbuda\",\"AI\":\"i-Anguilla\",\"AL\":\"i-Albania\",\"AM\":\"i-Armenia\",\"AO\":\"i-Angola\",\"AQ\":\"i-Antarctica\",\"AR\":\"i-Argentina\",\"AS\":\"i-American Samoa\",\"AT\":\"i-Austria\",\"AU\":\"i-Australia\",\"AW\":\"i-Aruba\",\"AX\":\"i-Åland Islands\",\"AZ\":\"i-Azerbaijan\",\"BA\":\"i-Bosnia ne-Herzegovina\",\"BB\":\"i-Barbados\",\"BD\":\"i-Bangladesh\",\"BE\":\"i-Belgium\",\"BF\":\"i-Burkina Faso\",\"BG\":\"i-Bulgaria\",\"BH\":\"i-Bahrain\",\"BI\":\"i-Burundi\",\"BJ\":\"i-Benin\",\"BL\":\"i-Saint Barthélemy\",\"BM\":\"i-Bermuda\",\"BN\":\"i-Brunei\",\"BO\":\"i-Bolivia\",\"BQ\":\"i-Caribbean Netherlands\",\"BR\":\"i-Brazil\",\"BS\":\"i-Bahamas\",\"BT\":\"i-Bhutan\",\"BV\":\"i-Bouvet Island\",\"BW\":\"iBotswana\",\"BY\":\"i-Belarus\",\"BZ\":\"i-Belize\",\"CA\":\"i-Canada\",\"CC\":\"i-Cocos (Keeling) Islands\",\"CD\":\"i-Congo - Kinshasa\",\"CF\":\"i-Central African Republic\",\"CG\":\"i-Congo - Brazzaville\",\"CH\":\"i-Switzerland\",\"CI\":\"i-Côte d’Ivoire\",\"CK\":\"i-Cook Islands\",\"CL\":\"i-Chile\",\"CM\":\"i-Cameroon\",\"CN\":\"i-China\",\"CO\":\"i-Colombia\",\"CP\":\"i-Clipperton Island\",\"CR\":\"i-Costa Rica\",\"CU\":\"i-Cuba\",\"CV\":\"i-Cape Verde\",\"CW\":\"i-Curaçao\",\"CX\":\"i-Christmas Island\",\"CY\":\"i-Cyprus\",\"CZ\":\"i-Czechia\",\"DE\":\"i-Germany\",\"DG\":\"i-Diego Garcia\",\"DJ\":\"i-Djibouti\",\"DK\":\"i-Denmark\",\"DM\":\"i-Dominica\",\"DO\":\"i-Dominican Republic\",\"DZ\":\"i-Algeria\",\"EA\":\"i-Cueta ne-Melilla\",\"EC\":\"i-Ecuador\",\"EE\":\"i-Estonia\",\"EG\":\"i-Egypt\",\"EH\":\"i-Western Sahara\",\"ER\":\"i-Eritrea\",\"ES\":\"i-Spain\",\"ET\":\"i-Ethiopia\",\"EU\":\"i-European Union\",\"EZ\":\"EZ\",\"FI\":\"i-Finland\",\"FJ\":\"i-Fiji\",\"FK\":\"i-Falkland Islands\",\"FM\":\"i-Micronesia\",\"FO\":\"i-Faroe Islands\",\"FR\":\"i-France\",\"GA\":\"i-Gabon\",\"GB\":\"i-United Kingdom\",\"GD\":\"i-Grenada\",\"GE\":\"i-Georgia\",\"GF\":\"i-French Guiana\",\"GG\":\"i-Guernsey\",\"GH\":\"i-Ghana\",\"GI\":\"i-Gibraltar\",\"GL\":\"i-Greenland\",\"GM\":\"i-Gambia\",\"GN\":\"i-Guinea\",\"GP\":\"i-Guadeloupe\",\"GQ\":\"i-Equatorial Guinea\",\"GR\":\"i-Greece\",\"GS\":\"i-South Georgia ne-South Sandwich Islands\",\"GT\":\"i-Guatemala\",\"GU\":\"i-Guam\",\"GW\":\"i-Guinea-Bissau\",\"GY\":\"i-Guyana\",\"HK\":\"i-Hong Kong SAR China\",\"HM\":\"I-Heard & McDonald Island\",\"HN\":\"i-Honduras\",\"HR\":\"i-Croatia\",\"HT\":\"i-Haiti\",\"HU\":\"i-Hungary\",\"IC\":\"i-Canary Islands\",\"ID\":\"i-Indonesia\",\"IE\":\"i-Ireland\",\"IL\":\"kwa-Israel\",\"IM\":\"i-Isle of Man\",\"IN\":\"i-India\",\"IO\":\"i-British Indian Ocean Territory\",\"IQ\":\"i-Iraq\",\"IR\":\"i-Iran\",\"IS\":\"i-Iceland\",\"IT\":\"i-Italy\",\"JE\":\"i-Jersey\",\"JM\":\"i-Jamaica\",\"JO\":\"i-Jordan\",\"JP\":\"i-Japan\",\"KE\":\"i-Kenya\",\"KG\":\"i-Kyrgyzstan\",\"KH\":\"i-Cambodia\",\"KI\":\"i-Kiribati\",\"KM\":\"i-Comoros\",\"KN\":\"i-Saint Kitts ne-Nevis\",\"KP\":\"i-North Korea\",\"KR\":\"i-South Korea\",\"KW\":\"i-Kuwait\",\"KY\":\"i-Cayman Islands\",\"KZ\":\"i-Kazakhstan\",\"LA\":\"i-Laos\",\"LB\":\"i-Lebanon\",\"LC\":\"i-Saint Lucia\",\"LI\":\"i-Liechtenstein\",\"LK\":\"i-Sri Lanka\",\"LR\":\"i-Liberia\",\"LS\":\"iLesotho\",\"LT\":\"i-Lithuania\",\"LU\":\"i-Luxembourg\",\"LV\":\"i-Latvia\",\"LY\":\"i-Libya\",\"MA\":\"i-Morocco\",\"MC\":\"i-Monaco\",\"MD\":\"i-Moldova\",\"ME\":\"i-Montenegro\",\"MF\":\"i-Saint Martin\",\"MG\":\"i-Madagascar\",\"MH\":\"i-Marshall Islands\",\"MK\":\"i-North Macedonia\",\"ML\":\"iMali\",\"MM\":\"i-Myanmar (Burma)\",\"MN\":\"i-Mongolia\",\"MO\":\"i-Macau SAR China\",\"MP\":\"i-Northern Mariana Islands\",\"MQ\":\"i-Martinique\",\"MR\":\"i-Mauritania\",\"MS\":\"i-Montserrat\",\"MT\":\"i-Malta\",\"MU\":\"i-Mauritius\",\"MV\":\"i-Maldives\",\"MW\":\"iMalawi\",\"MX\":\"i-Mexico\",\"MY\":\"i-Malaysia\",\"MZ\":\"i-Mozambique\",\"NA\":\"i-Namibia\",\"NC\":\"i-New Caledonia\",\"NE\":\"i-Niger\",\"NF\":\"i-Norfolk Island\",\"NG\":\"i-Nigeria\",\"NI\":\"i-Nicaragua\",\"NL\":\"i-Netherlands\",\"NO\":\"i-Norway\",\"NP\":\"i-Nepal\",\"NR\":\"i-Nauru\",\"NU\":\"i-Niue\",\"NZ\":\"i-New Zealand\",\"OM\":\"i-Oman\",\"PA\":\"i-Panama\",\"PE\":\"i-Peru\",\"PF\":\"i-French Polynesia\",\"PG\":\"i-Papua New Guinea\",\"PH\":\"i-Philippines\",\"PK\":\"i-Pakistan\",\"PL\":\"i-Poland\",\"PM\":\"i-Saint Pierre kanye ne-Miquelon\",\"PN\":\"i-Pitcairn Islands\",\"PR\":\"i-Puerto Rico\",\"PS\":\"i-Palestinian Territories\",\"PT\":\"i-Portugal\",\"PW\":\"i-Palau\",\"PY\":\"i-Paraguay\",\"QA\":\"i-Qatar\",\"QO\":\"i-Outlying Oceania\",\"RE\":\"i-Réunion\",\"RO\":\"i-Romania\",\"RS\":\"i-Serbia\",\"RU\":\"i-Russia\",\"RW\":\"i-Rwanda\",\"SA\":\"i-Saudi Arabia\",\"SB\":\"i-Solomon Islands\",\"SC\":\"i-Seychelles\",\"SD\":\"i-Sudan\",\"SE\":\"i-Sweden\",\"SG\":\"i-Singapore\",\"SH\":\"i-St. Helena\",\"SI\":\"i-Slovenia\",\"SJ\":\"i-Svalbard ne-Jan Mayen\",\"SK\":\"i-Slovakia\",\"SL\":\"i-Sierra Leone\",\"SM\":\"i-San Marino\",\"SN\":\"i-Senegal\",\"SO\":\"i-Somalia\",\"SR\":\"i-Suriname\",\"SS\":\"i-South Sudan\",\"ST\":\"i-São Tomé kanye ne-Príncipe\",\"SV\":\"i-El Salvador\",\"SX\":\"i-Sint Maarten\",\"SY\":\"i-Syria\",\"SZ\":\"i-Swaziland\",\"TA\":\"i-Tristan da Cunha\",\"TC\":\"i-Turks ne-Caicos Islands\",\"TD\":\"i-Chad\",\"TF\":\"i-French Southern Territories\",\"TG\":\"i-Togo\",\"TH\":\"i-Thailand\",\"TJ\":\"i-Tajikistan\",\"TK\":\"i-Tokelau\",\"TL\":\"i-Timor-Leste\",\"TM\":\"i-Turkmenistan\",\"TN\":\"i-Tunisia\",\"TO\":\"i-Tonga\",\"TR\":\"i-Turkey\",\"TT\":\"i-Trinidad ne-Tobago\",\"TV\":\"i-Tuvalu\",\"TW\":\"i-Taiwan\",\"TZ\":\"i-Tanzania\",\"UA\":\"i-Ukraine\",\"UG\":\"i-Uganda\",\"UM\":\"I-U.S. Outlying Islands\",\"UN\":\"I-United Nations\",\"US\":\"i-United States\",\"UY\":\"i-Uruguay\",\"UZ\":\"i-Uzbekistan\",\"VA\":\"i-Vatican City\",\"VC\":\"i-Saint Vincent ne-Grenadines\",\"VE\":\"i-Venezuela\",\"VG\":\"i-British Virgin Islands\",\"VI\":\"i-U.S. Virgin Islands\",\"VN\":\"i-Vietnam\",\"VU\":\"i-Vanuatu\",\"WF\":\"i-Wallis ne-Futuna\",\"WS\":\"i-Samoa\",\"XA\":\"Pseudo-Accents\",\"XB\":\"Pseudo-Bidi\",\"XK\":\"i-Kosovo\",\"YE\":\"i-Yemen\",\"YT\":\"i-Mayotte\",\"ZA\":\"iNingizimu Afrika\",\"ZM\":\"i-Zambia\",\"ZW\":\"iZimbabwe\",\"ZZ\":\"iSifunda esingaziwa\"},\"short\":{\"GB\":\"i-U.K.\",\"HK\":\"i-Hong Kong\",\"MO\":\"i-Macau\",\"PS\":\"i-Palestine\",\"UN\":\"ifulegi\",\"US\":\"i-U.S\"},\"narrow\":{}},\"script\":{\"long\":{\"Adlm\":\"Adlm\",\"Aghb\":\"Aghb\",\"Ahom\":\"Ahom\",\"Arab\":\"isi-Arabic\",\"Armi\":\"Armi\",\"Armn\":\"isi-Armenian\",\"Avst\":\"Avst\",\"Bali\":\"Bali\",\"Bamu\":\"Bamu\",\"Bass\":\"Bass\",\"Batk\":\"Batk\",\"Beng\":\"isi-Bangla\",\"Bhks\":\"Bhks\",\"Bopo\":\"isi-Bopomofo\",\"Brah\":\"Brah\",\"Brai\":\"i-Braille\",\"Bugi\":\"Bugi\",\"Buhd\":\"Buhd\",\"Cakm\":\"Cakm\",\"Cans\":\"Cans\",\"Cari\":\"Cari\",\"Cham\":\"Cham\",\"Cher\":\"Cher\",\"Copt\":\"Copt\",\"Cprt\":\"Cprt\",\"Cyrl\":\"isi-Cyrillic\",\"Deva\":\"isi-Devanagari\",\"Dogr\":\"Dogr\",\"Dsrt\":\"Dsrt\",\"Dupl\":\"Dupl\",\"Egyp\":\"Egyp\",\"Elba\":\"Elba\",\"Elym\":\"Elym\",\"Ethi\":\"isi-Ethiopic\",\"Geor\":\"isi-Georgian\",\"Glag\":\"Glag\",\"Gong\":\"Gong\",\"Gonm\":\"Gonm\",\"Goth\":\"Goth\",\"Gran\":\"Gran\",\"Grek\":\"isi-Greek\",\"Gujr\":\"isi-Gujarati\",\"Guru\":\"isi-Gurmukhi\",\"Hanb\":\"isi-Hanb\",\"Hang\":\"isi-Hangul\",\"Hani\":\"isi-Han\",\"Hano\":\"Hano\",\"Hans\":\"enziwe lula\",\"Hant\":\"okosiko\",\"Hatr\":\"Hatr\",\"Hebr\":\"isi-Hebrew\",\"Hira\":\"isi-Hiragana\",\"Hluw\":\"Hluw\",\"Hmng\":\"Hmng\",\"Hmnp\":\"Hmnp\",\"Hrkt\":\"i-Japanese syllabaries\",\"Hung\":\"Hung\",\"Ital\":\"Ital\",\"Jamo\":\"isi-Jamo\",\"Java\":\"Java\",\"Jpan\":\"isi-Japanese\",\"Kali\":\"Kali\",\"Kana\":\"isi-Katakana\",\"Khar\":\"Khar\",\"Khmr\":\"isi-Khmer\",\"Khoj\":\"Khoj\",\"Knda\":\"isi-Kannada\",\"Kore\":\"isi-Korean\",\"Kthi\":\"Kthi\",\"Lana\":\"Lana\",\"Laoo\":\"isi-Lao\",\"Latn\":\"isi-Latin\",\"Lepc\":\"Lepc\",\"Limb\":\"Limb\",\"Lina\":\"Lina\",\"Linb\":\"Linb\",\"Lisu\":\"Lisu\",\"Lyci\":\"Lyci\",\"Lydi\":\"Lydi\",\"Mahj\":\"Mahj\",\"Maka\":\"Maka\",\"Mand\":\"Mand\",\"Mani\":\"Mani\",\"Marc\":\"Marc\",\"Medf\":\"Medf\",\"Mend\":\"Mend\",\"Merc\":\"Merc\",\"Mero\":\"Mero\",\"Mlym\":\"isi-Malayalam\",\"Modi\":\"Modi\",\"Mong\":\"isi-Mongolian\",\"Mroo\":\"Mroo\",\"Mtei\":\"Mtei\",\"Mult\":\"Mult\",\"Mymr\":\"isi-Myanmar\",\"Nand\":\"Nand\",\"Narb\":\"Narb\",\"Nbat\":\"Nbat\",\"Newa\":\"Newa\",\"Nkoo\":\"Nkoo\",\"Nshu\":\"Nshu\",\"Ogam\":\"Ogam\",\"Olck\":\"Olck\",\"Orkh\":\"Orkh\",\"Orya\":\"isi-Odia\",\"Osge\":\"Osge\",\"Osma\":\"Osma\",\"Palm\":\"Palm\",\"Pauc\":\"Pauc\",\"Perm\":\"Perm\",\"Phag\":\"Phag\",\"Phli\":\"Phli\",\"Phlp\":\"Phlp\",\"Phnx\":\"Phnx\",\"Plrd\":\"Plrd\",\"Prti\":\"Prti\",\"Qaag\":\"Qaag\",\"Rjng\":\"Rjng\",\"Rohg\":\"Rohg\",\"Runr\":\"Runr\",\"Samr\":\"Samr\",\"Sarb\":\"Sarb\",\"Saur\":\"Saur\",\"Sgnw\":\"Sgnw\",\"Shaw\":\"Shaw\",\"Shrd\":\"Shrd\",\"Sidd\":\"Sidd\",\"Sind\":\"Sind\",\"Sinh\":\"isi-Sinhala\",\"Sogd\":\"Sogd\",\"Sogo\":\"Sogo\",\"Sora\":\"Sora\",\"Soyo\":\"Soyo\",\"Sund\":\"Sund\",\"Sylo\":\"Sylo\",\"Syrc\":\"Syrc\",\"Tagb\":\"Tagb\",\"Takr\":\"Takr\",\"Tale\":\"Tale\",\"Talu\":\"Talu\",\"Taml\":\"isi-Tamil\",\"Tang\":\"Tang\",\"Tavt\":\"Tavt\",\"Telu\":\"isi-Telugu\",\"Tfng\":\"Tfng\",\"Tglg\":\"Tglg\",\"Thaa\":\"isi-Thaana\",\"Thai\":\"isi-Thai\",\"Tibt\":\"i-Tibetan\",\"Tirh\":\"Tirh\",\"Ugar\":\"Ugar\",\"Vaii\":\"Vaii\",\"Wara\":\"Wara\",\"Wcho\":\"Wcho\",\"Xpeo\":\"Xpeo\",\"Xsux\":\"Xsux\",\"Yiii\":\"Yiii\",\"Zanb\":\"Zanb\",\"Zinh\":\"Zinh\",\"Zmth\":\"i-Mathematical Notation\",\"Zsye\":\"i-Emoji\",\"Zsym\":\"amasimbuli\",\"Zxxx\":\"okungabhaliwe\",\"Zyyy\":\"jwayelekile\",\"Zzzz\":\"iskripthi esingaziwa\"},\"short\":{},\"narrow\":{}},\"currency\":{\"long\":{\"ADP\":\"ADP\",\"AED\":\"i-Dirham yase-United Arab Emirates\",\"AFA\":\"AFA\",\"AFN\":\"i-Afghan Afghani\",\"ALK\":\"ALK\",\"ALL\":\"i-Albanian Lek\",\"AMD\":\"i-Armenian Dram\",\"ANG\":\"i-Netherlands Antillean Guilder\",\"AOA\":\"i-Angolan Kwanza\",\"AOK\":\"AOK\",\"AON\":\"AON\",\"AOR\":\"AOR\",\"ARA\":\"ARA\",\"ARL\":\"ARL\",\"ARM\":\"ARM\",\"ARP\":\"ARP\",\"ARS\":\"i-Argentina Peso\",\"ATS\":\"ATS\",\"AUD\":\"i-Austrilian Dollar\",\"AWG\":\"i-Aruban Florin\",\"AZM\":\"AZM\",\"AZN\":\"i-Azerbaijani Manat\",\"BAD\":\"BAD\",\"BAM\":\"i-Bosnia-Herzegovina Convertible Mark\",\"BAN\":\"BAN\",\"BBD\":\"i-Barbadian Dollar\",\"BDT\":\"i-Bangladeshi Taka\",\"BEC\":\"BEC\",\"BEF\":\"BEF\",\"BEL\":\"BEL\",\"BGL\":\"BGL\",\"BGM\":\"BGM\",\"BGN\":\"i-Bulgarian Lev\",\"BGO\":\"BGO\",\"BHD\":\"i-Bahraini Dinar\",\"BIF\":\"i-Burundian Franc\",\"BMD\":\"i-Bermudan Dollar\",\"BND\":\"i-Brunei Dollar\",\"BOB\":\"i-Bolivian Boliviano\",\"BOL\":\"BOL\",\"BOP\":\"BOP\",\"BOV\":\"BOV\",\"BRB\":\"BRB\",\"BRC\":\"BRC\",\"BRE\":\"BRE\",\"BRL\":\"i-Brazilian Real\",\"BRN\":\"BRN\",\"BRR\":\"BRR\",\"BRZ\":\"BRZ\",\"BSD\":\"i-Bahamian Dollar\",\"BTN\":\"i-Bhutanese Ngultrum\",\"BUK\":\"BUK\",\"BWP\":\"i-Botswana Pula\",\"BYB\":\"BYB\",\"BYN\":\"i-Belarusian Ruble\",\"BYR\":\"i-Belarusian Ruble (2000–2016)\",\"BZD\":\"i-Belize Dollar\",\"CAD\":\"i-Candian Dollar\",\"CDF\":\"i-Congolese Franc\",\"CHE\":\"CHE\",\"CHF\":\"i-Swiss Franc\",\"CHW\":\"CHW\",\"CLE\":\"CLE\",\"CLF\":\"CLF\",\"CLP\":\"i-Chilean Peso\",\"CNH\":\"CNH\",\"CNX\":\"CNX\",\"CNY\":\"i-Chinese Yuan\",\"COP\":\"i-Colombian Peso\",\"COU\":\"COU\",\"CRC\":\"i-Costa Rican Colón\",\"CSD\":\"CSD\",\"CSK\":\"CSK\",\"CUC\":\"i-Cuban Convertable Peso\",\"CUP\":\"i-Cuban Peso\",\"CVE\":\"i-Cape Verdean Escudo\",\"CYP\":\"CYP\",\"CZK\":\"i-Czech Republic Koruna\",\"DDM\":\"DDM\",\"DEM\":\"DEM\",\"DJF\":\"i-Djiboutian Franc\",\"DKK\":\"i-Danish Krone\",\"DOP\":\"i-Dominican Peso\",\"DZD\":\"i-Algerian Dinar\",\"ECS\":\"ECS\",\"ECV\":\"ECV\",\"EEK\":\"EEK\",\"EGP\":\"i-Egyptian Pound\",\"ERN\":\"i-Eritrean Nakfa\",\"ESA\":\"ESA\",\"ESB\":\"ESB\",\"ESP\":\"ESP\",\"ETB\":\"i-Ethopian Birr\",\"EUR\":\"i-Euro\",\"FIM\":\"FIM\",\"FJD\":\"i-Fijian Dollar\",\"FKP\":\"i-Falkland Islands Pound\",\"FRF\":\"FRF\",\"GBP\":\"i-British Pound\",\"GEK\":\"GEK\",\"GEL\":\"i-Georgian Lari\",\"GHC\":\"GHC\",\"GHS\":\"i-Ghanaian Cedi\",\"GIP\":\"i-Gibraltar Pound\",\"GMD\":\"i-Gambian Dalasi\",\"GNF\":\"i-Gunean Franc\",\"GNS\":\"GNS\",\"GQE\":\"GQE\",\"GRD\":\"GRD\",\"GTQ\":\"i-Guatemalan Quetzal\",\"GWE\":\"GWE\",\"GWP\":\"GWP\",\"GYD\":\"i-Guyanaese Dollar\",\"HKD\":\"i-Hong Kong Dollar\",\"HNL\":\"i-Honduran Lempira\",\"HRD\":\"HRD\",\"HRK\":\"i-Croatian Kuna\",\"HTG\":\"i-Haitian Gourde\",\"HUF\":\"i-Hungarian Forint\",\"IDR\":\"i-Indonesian Rupiah\",\"IEP\":\"IEP\",\"ILP\":\"ILP\",\"ILR\":\"ILR\",\"ILS\":\"i-Israeli New Sheqel\",\"INR\":\"i-Indian Rupee\",\"IQD\":\"i-Iraqi Dinar\",\"IRR\":\"i-Iranian Rial\",\"ISJ\":\"ISJ\",\"ISK\":\"i-Icelandic Króna\",\"ITL\":\"ITL\",\"JMD\":\"i-Jamaican Dollar\",\"JOD\":\"i-Jordanian Dinar\",\"JPY\":\"i-Japanese Yen\",\"KES\":\"i-Kenyan Shilling\",\"KGS\":\"i-Kyrgystani Som\",\"KHR\":\"i-Cambodian Riel\",\"KMF\":\"i-Comorian Franc\",\"KPW\":\"i-North Korean Won\",\"KRH\":\"KRH\",\"KRO\":\"KRO\",\"KRW\":\"i-South Korean Won\",\"KWD\":\"i-Kuwaiti Dinar\",\"KYD\":\"i-Cayman Islands Dollar\",\"KZT\":\"i-Kazakhstani Tenge\",\"LAK\":\"i-Laotian Kip\",\"LBP\":\"i-Lebanese Pound\",\"LKR\":\"i-Sri Lankan Rupee\",\"LRD\":\"i-Liberian Dollar\",\"LSL\":\"i-Lesotho Loti\",\"LTL\":\"i-Lithuanian Litas\",\"LTT\":\"LTT\",\"LUC\":\"LUC\",\"LUF\":\"LUF\",\"LUL\":\"LUL\",\"LVL\":\"i-Latvian Lats\",\"LVR\":\"LVR\",\"LYD\":\"i-Libyan Dinar\",\"MAD\":\"i-Moroccan Dirham\",\"MAF\":\"MAF\",\"MCF\":\"MCF\",\"MDC\":\"MDC\",\"MDL\":\"i-Moldovan Leu\",\"MGA\":\"i-Malagasy Ariary\",\"MGF\":\"MGF\",\"MKD\":\"i-Macedonian Denar\",\"MKN\":\"MKN\",\"MLF\":\"MLF\",\"MMK\":\"i-Myanma Kyat\",\"MNT\":\"i-Mongolian Tugrik\",\"MOP\":\"i-Macanese Pataca\",\"MRO\":\"i-Mauritanian Ouguiya (1973–2017)\",\"MRU\":\"i-Mauritanian Ouguiya\",\"MTL\":\"MTL\",\"MTP\":\"MTP\",\"MUR\":\"i-Mauritian Rupee\",\"MVP\":\"MVP\",\"MVR\":\"i-Maldivian Rufiyana\",\"MWK\":\"i-Malawian Kwacha\",\"MXN\":\"i-Mexican Peso\",\"MXP\":\"MXP\",\"MXV\":\"MXV\",\"MYR\":\"i-Malaysian Ringgit\",\"MZE\":\"MZE\",\"MZM\":\"MZM\",\"MZN\":\"i-Mozambican Metical\",\"NAD\":\"i-Namibian Dollar\",\"NGN\":\"i-Nigerian Naira\",\"NIC\":\"NIC\",\"NIO\":\"i-Nicaraguan Córdoba\",\"NLG\":\"NLG\",\"NOK\":\"i-Norwegian Krone\",\"NPR\":\"i-Nepalese Rupee\",\"NZD\":\"i-New Zealand Dollar\",\"OMR\":\"i-Omani Rial\",\"PAB\":\"i-Panamanian Balboa\",\"PEI\":\"PEI\",\"PEN\":\"i-Peruvian Nuevo Sol\",\"PES\":\"PES\",\"PGK\":\"i-Papua New Guinean Kina\",\"PHP\":\"i-Philippine Peso\",\"PKR\":\"i-Pakistani Rupee\",\"PLN\":\"i-Polish Zloty\",\"PLZ\":\"PLZ\",\"PTE\":\"PTE\",\"PYG\":\"i-Paraguayan Guarani\",\"QAR\":\"i-Qatari Rial\",\"RHD\":\"RHD\",\"ROL\":\"ROL\",\"RON\":\"i-Romanian Leu\",\"RSD\":\"i-Serbian Dinar\",\"RUB\":\"i-Russian Ruble\",\"RUR\":\"RUR\",\"RWF\":\"i-Rwandan Franc\",\"SAR\":\"i-Saudi Riyal\",\"SBD\":\"i-Solomon Islands Dollar\",\"SCR\":\"i-Seychellois Rupee\",\"SDD\":\"SDD\",\"SDG\":\"i-Sudanese Pound\",\"SDP\":\"SDP\",\"SEK\":\"i-Swedish Krona\",\"SGD\":\"i-Singapore Dollar\",\"SHP\":\"i-Saint Helena Pound\",\"SIT\":\"SIT\",\"SKK\":\"SKK\",\"SLL\":\"i-Sierra Leonean Leone\",\"SOS\":\"i-Somali Shilling\",\"SRD\":\"i-Surinamese Dollar\",\"SRG\":\"SRG\",\"SSP\":\"i-South Sudanese Pound\",\"STD\":\"i-São Tomé kanye ne-Príncipe Dobra (1977–2017)\",\"STN\":\"i-São Tomé kanye ne-Príncipe Dobra\",\"SUR\":\"SUR\",\"SVC\":\"SVC\",\"SYP\":\"i-Syrian Pound\",\"SZL\":\"i-Swazi Lilangeni\",\"THB\":\"i-Thai Baht\",\"TJR\":\"TJR\",\"TJS\":\"i-Tajikistani Somoni\",\"TMM\":\"TMM\",\"TMT\":\"i-Turkmenistani Manat\",\"TND\":\"i-Tunisian Dinar\",\"TOP\":\"i-Tongan Paʻanga\",\"TPE\":\"TPE\",\"TRL\":\"TRL\",\"TRY\":\"i-Turkish Lira\",\"TTD\":\"i-Trinidad and Tobago Dollar\",\"TWD\":\"i-New Taiwan Dollar\",\"TZS\":\"i-Tanzanian Shilling\",\"UAH\":\"i-Ukrainian Hryvnia\",\"UAK\":\"UAK\",\"UGS\":\"UGS\",\"UGX\":\"i-Ugandan Shilling\",\"USD\":\"i-US Dollar\",\"USN\":\"USN\",\"USS\":\"USS\",\"UYI\":\"UYI\",\"UYP\":\"UYP\",\"UYU\":\"i-Uruguayan Peso\",\"UYW\":\"UYW\",\"UZS\":\"i-Uzbekistan Som\",\"VEB\":\"VEB\",\"VEF\":\"i-Venezuelan Bolívar (2008–2018)\",\"VES\":\"i-Venezuelan Bolívar\",\"VND\":\"i-Vietnamese Dong\",\"VNN\":\"VNN\",\"VUV\":\"i-Vanuatu Vatu\",\"WST\":\"i-Samoan Tala\",\"XAF\":\"i-Central African CFA Franc\",\"XAG\":\"XAG\",\"XAU\":\"XAU\",\"XBA\":\"XBA\",\"XBB\":\"XBB\",\"XBC\":\"XBC\",\"XBD\":\"XBD\",\"XCD\":\"i-East Caribbean Dollar\",\"XDR\":\"XDR\",\"XEU\":\"XEU\",\"XFO\":\"XFO\",\"XFU\":\"XFU\",\"XOF\":\"i-West African CFA Franc\",\"XPD\":\"XPD\",\"XPF\":\"i-CFP Franc\",\"XPT\":\"XPT\",\"XRE\":\"XRE\",\"XSU\":\"XSU\",\"XTS\":\"XTS\",\"XUA\":\"XUA\",\"XXX\":\"imali engaziwa\",\"YDD\":\"YDD\",\"YER\":\"i-Yemeni Rial\",\"YUD\":\"YUD\",\"YUM\":\"YUM\",\"YUN\":\"YUN\",\"YUR\":\"YUR\",\"ZAL\":\"ZAL\",\"ZAR\":\"i-South African Rand\",\"ZMK\":\"i-Zambian Kwacha (1968–2012)\",\"ZMW\":\"i-Zambian Kwacha\",\"ZRN\":\"ZRN\",\"ZRZ\":\"ZRZ\",\"ZWD\":\"ZWD\",\"ZWL\":\"ZWL\",\"ZWR\":\"ZWR\"},\"short\":{},\"narrow\":{}}},\"patterns\":{\"locale\":\"{0} ({1})\"}}},\"availableLocales\":[\"zu\"],\"aliases\":{},\"parentLocales\":{}}\n";
                            String content = "123";
//                            for (int i = 0; i < 20; i++) {
//                                content += content;
//                            }
                            byte[] conBtr = content.getBytes(StandardCharsets.UTF_8);
                            log.info("原文字节内容：{}", conBtr.length);
                            for (int i = 0; i < 20; i++) {
                                socketChannel.write(ByteBuffer.wrap(conBtr));
                            }
                            final int write = socketChannel.write(ByteBuffer.wrap(conBtr));
                            log.info("实际写的数据长度：{}", write);
                            if (write < conBtr.length) {
                                // 数据没写完，需要继续写，此时注册写事件
                                selectedKey.interestOps(selectedKey.interestOps() + SelectionKey.OP_WRITE);
                            }
                            log.info("继续写的内容：{}", socketChannel.write(ByteBuffer.wrap("hello world\r\n".getBytes(StandardCharsets.UTF_8))));
                            // 表示一次事件读取完毕
                            // 重新向通道注册一个事件
                            // selectedKey.interestOps(SelectionKey.OP_WRITE);
                        } else if (selectedKey.isWritable()) {
                            // 如果内核缓冲区没有满，就会一直触发写事件
                            log.info("有数据可以写");
                            SocketChannel socketChannel = (SocketChannel) selectedKey.channel();
                            socketChannel.write(ByteBuffer.wrap("hello world\r\n".getBytes(StandardCharsets.UTF_8)));
                            // 数据写完，清除写事件
                            selectedKey.interestOps(selectedKey.interestOps() - SelectionKey.OP_WRITE);
                        }
                        // 删除该事件，避免重复
                        iterator.remove();
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (serverSocketChannel != null) {
                    serverSocketChannel.close();
                }
                if (selector != null) {
                    selector.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static boolean isInterest(SelectionKey selectionKey, int ops) {
        final int interestOps = selectionKey.interestOps();
        boolean result = (interestOps & ops) == ops;
        return result;
    }
}
